home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / egebook.lha / ege.book / 1 / Scheduling.C < prev   
C/C++ Source or Header  |  1992-06-04  |  2KB  |  67 lines

  1. #include <stdio.h>
  2.  
  3. class Teacher {
  4.   char *name;               // name of teacher
  5. public:
  6.   void setName(char *newName){   // member function
  7.     name = newName;
  8.   };
  9.   void print(){
  10.     printf("the teachers name is: %s \n", name);
  11.   };
  12. };
  13.  
  14. class Student{
  15.   char *name;       // name of student
  16. };
  17.  
  18. class Course {
  19.   char *number;          // course number as string
  20.   char *time;            // time slot as string
  21.   Student *students[25]; // array of students in class
  22. public:
  23.   Teacher *teacher;      // teacher for class
  24.   void initialize(char *n, char *t){
  25.     number = n;
  26.     time = t;
  27.   };
  28. };
  29.  
  30. class Schedule {
  31.   Course *offerings[10];    // array of courses
  32.   int offered;              // number of courses offered
  33. public:
  34.   Schedule():offered(0){};
  35.   void assign(Course *c, Teacher *t){
  36.     if (offered < 10) {
  37.       offerings[offered++] = c;
  38.       c->teacher = t;       // NOTE: teacher field of course c
  39.                             //  is accessed with operator "->"
  40.     } else
  41.       printf("Schedule full ! \n");
  42.   };
  43. };
  44.  
  45. main() {
  46.   Schedule s;              // a schedule object
  47.   Teacher t1, t2;          // teacher objects
  48.   Course c1, c2;           // course objects
  49.  
  50.   t1.setName("Joe Teach");
  51.   t2.setName("John Prof");
  52.   c1.initialize("COP 4225","MW 1030-1200");
  53.   c2.initialize("COP 6611","TR 1030-1200");
  54.  
  55.   printf("Welcome to the Course Scheduling system\n");
  56.  
  57.   s.assign(&c1, &t1);        // assign function expects
  58.   s.assign(&c2, &t2);        // pointer arguments
  59.  
  60.   printf("Teacher of first course: ");
  61.   c1.teacher->print();
  62.   printf("Teacher of second course: ");
  63.   c2.teacher->print();
  64.  
  65.   // ... rest of application
  66. }
  67.